<?php
// +----------------------------------------------------------------------
// | EasyAdmin
// +----------------------------------------------------------------------
// | PHP交流群: 763822524
// +----------------------------------------------------------------------
// | 开源协议  https://mit-license.org 
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zhongshaofa/EasyAdmin
// +----------------------------------------------------------------------
namespace app\model\api;

use app\model\admin\sky\SkyMagicData;
use app\model\admin\sky\SkyMagicDetail;
use laytp\BaseModel;
use think\model\concern\SoftDelete;

class SkyMagic extends BaseModel
{
    use SoftDelete;
    protected $name = 'sky_magic';

    /**
     * 今日魔法
     * @param $date
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function todayMagic($date){
        $weekarray = [7,1,2,3,4,5,6];
        $date_type = $weekarray[date("w",strtotime($date))];
        $id = $this->where("type",$date_type)->value("id");
        $magic_data_ids = (new SkyMagicDetail())->where('magic_id',$id)->column("magic_data_id");
        return (new SkyMagicData())->field('magic_name as name,magic_img as icon')
            ->whereIn("id",$magic_data_ids)->order('id desc')->cache(true)->select()->toArray();
    }
}